/** 
 * Copyright 2010 Erlacher Felix, Estgfaeller Wolfgang, Ferula Patrick
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package at.socialconference.web.client.ui;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Provides the main view of the SCweb application with the underlying
 * DockLayoutPanel to manage the content of the view.
 * 
 */
public class SCwebView extends Composite {

	private Menu menu;
	private SimplePanel north = new SimplePanel();
	private SimplePanel west = new SimplePanel();
	private SimplePanel middle = new SimplePanel();


	
	public SCwebView() {
		try {
			DockLayoutPanel dockLayoutPanel = new DockLayoutPanel(Unit.PX);
			this.initWidget(dockLayoutPanel);
			dockLayoutPanel.setSize("1200px", "1000px");

			HTML htmlWelcome = new HTML("<h1>Social Conference Project</h1>", true);
			htmlWelcome.setStyleName("h1");
			htmlWelcome.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
			north.setStyleName("titlebackground");
			north.add(htmlWelcome);
			dockLayoutPanel.addNorth(north, 100);
			west.setStyleName("menupanel");

			menu = new Menu();

			west.add(menu);
			dockLayoutPanel.addWest(west, 200);
			middle.setStyleName("SCwebView-center");

			dockLayoutPanel.add(middle);
		} catch (Exception e) {
			Window.alert(e.getLocalizedMessage());
		}

	}

	/**
	 * Updates the middle of the root DockLayoutPanel
	 * 
	 * @param w
	 */
	public void updateMiddle(Widget w) {
		middle.clear();
		middle.add(w);
	}

	/**
	 * Updates the menu to the given status
	 * 
	 * @param loggedIn
	 *            true for logged in
	 */
	public void updateMenu(boolean loggedIn) {
		menu.setLoggedIn(loggedIn);
	}

}
